#!/bin/sh
        export JAVA_HOME=/root/buildbox/jdk1.8.0_151
        export MAVN_HOME=/root/buildbox/apache-maven-3.3.3

        export CODEDEX_PATH=/root/buildbox/CodeDEX_V3
        export FORTIFY_HOME=$CODEDEX_PATH/tool/tools/fortify_17.20
        export COVERITY_HOME=$CODEDEX_PATH/tool/tools/coverity_2018.01
        export ZA_HOME=$CODEDEX_PATH/tool/7za/Linux
        export COMPILER_EXTRACT=$CODEDEX_PATH/compiler-extract
        export CODEMARS_HOME=$CODEDEX_PATH/tool/tools/codemars_Newest

        #path
        export PATH=$JAVA_HOME/bin:$MAVN_HOME/bin:$FORTIFY_HOME/bin:$COVERITY_HOME/bin:$COMPILER_EXTRACT/bin:$CODEMARS_HOME/bin:$PATH

        # FORTIFY_BUILD_ID�������Լ������IDֵ�����ID�������֡���ĸ���»�����ɣ���֧�ְ����л���-
        export FORTIFY_BUILD_ID=fuxi_codedex_test1
        export language=java

        #ʹ�û�������INTER_DIR(�м��ļ�Ŀ¼)��SRC_WS(Դ��·��)��SCAN_DIR(��ɨ��Ĵ������·��)
        export inter_dir=$inter_dir
        export codemars_tmp_dir=$inter_dir/codemars_tmp
        export cov_tmp_dir=$inter_dir/cov_tmp
        export for_tmp_dir=$inter_dir/for_tmp
        export project_root=$SRC_WS/$SCAN_DIR

        rm -rf "$inter_dir"

        cd "$CODEMARS_HOME" || return
        sh CodeMars.sh -j -source "$project_root" -output "$codemars_tmp_dir"/CodeMars.json

        cd "$project_root" || return
        cov-build --dir "$cov_tmp_dir" mvn clean install -Dmaven.test.skip=true

        cd $CODEDEX_PATH/compiler-extract/bin || return
        compiler-extract -fh $FORTIFY_HOME -lang $language -dir "$inter_dir" -b $FORTIFY_BUILD_ID

        cd "$inter_dir" || return
        sourceanalyzer -b $FORTIFY_BUILD_ID -Dcom.fortify.sca.ProjectRoot="$for_tmp_dir" -export-build-session $FORTIFY_BUILD_ID.mbs

        cd "$cov_tmp_dir" || return
        $ZA_HOME/7za a -tzip coverity.zip ./* -r
        mv coverity.zip "$inter_dir"

        cd "$inter_dir" || return
        $ZA_HOME/7za a -tzip fortify.zip $FORTIFY_BUILD_ID.mbs
        mv fortify.zip "$inter_dir"  

        cd "$codemars_tmp_dir" || return
        zip codemars.zip CodeMars.json 
        cp codemars.zip "$inter_dir"/